import { ipcMain } from "electron";
import type { UnzipFileArgs } from "@common/archives-file-types";
import { UnzipTask } from "@electron/main/task/unzip-task";
import { getWindow } from "@electron/main/ipc-service/window-holder";

const tasks = new Map<string, UnzipTask>();

ipcMain.on("archive-file:unzip", async (event, args: UnzipFileArgs) => {
  const task = new UnzipTask(args.id, args.archiveFile, args.outputDir, getWindow(event.sender.id));
  tasks.set(args.id, task);
  task.on("complete", () => tasks.delete(args.id));
  task.start();
});
